var template = require('../../../../template/backstageTemplate.js');
var t = function (t) {
    return t && t.__esModule ? t : {
      default: t
    };
  }(),
  app = getApp(),
  e = 0;
var page = 1;
Page({
  data: {
    curHdIndex: 1,
    index: 5,
    keyword: "",

    pageOne: 0,
    pageTwo: 0,
    prenumber: 20,
    tsid: 1,
    loadingBoo: !0,
    moreBooOne: !0,
    moreBooTwo: !0,
    communityListOne: [],
    communityListTwo: [],
    url: "patient/community/list/",
    oneBoo: !1,
    twoBoo: !1,
    mask: !0,
    currindex: 0,
    itemList: [],
    ismore: true,
    teamitem: ['我创建的', '我加入的'],
    teamindex: 0,
    myfound: [{}, {}, {}],
    myadd: [{}, {}],
    ispopup: false,
    isstate: false,
    isscreen: false,
    popupindex: 0,
    screenindex: 0,
    compre: ["综合排序", '回答次数', "星级评分", '响应时间'],
    screen: ["未审核", '已审核'],
    doctitle: ["医师", '主治医师', '副主任医师', '主任医师'],
    depart: ['皮肤科', '皮肤病科'],
    stateitem1: -1,
    stateitem2: -1,
    stateitem3: -1,
    stateitem4: -1,
    hid:"",
    order:"",
    zhicheng:"",
    keshi:"",
    status:"",
    list:[],
    page:0,
    pagesize:10
  },
  statelistbtn: function (e) {
    
    const dexs = e.currentTarget.dataset.dexs;
    var id = e.currentTarget.dataset.id;
    if (dexs == 1) {
      let index = e.currentTarget.dataset.index;
      this.setData({
        stateitem1: index,
        zhicheng:id
      })
    } else if (dexs == 2) {
      let index = e.currentTarget.dataset.index;
      this.setData({
        stateitem2: index,
        keshi:id
      })
    } 
  },
  // 搜索输入
  changes: function (e) {
    this.setData({
      keyword: e.detail.value
    })
  },
  search: function () {
    var that = this;
    that.setData({
      list: [],
      page: 0
    })
    that.getList();
  },
  resalts: function () {
    this.setData({
      stateitem1: -1,
      stateitem2: -1,
      stateitem3: -1,
      stateitem4: -1,
      zhicheng:"",
      keshi:"",
      page:0,
      list:[]
    })
  },
  statesuss: function () {
    this.setData({
      ispopup: false,
      isstate: false,
      isscreen: false,
      page:0,
      list:[]
    })
    this.getList();
  },
  teamindex: function () {
    // wx.navigateTo({
    //   url: '/hyb_yl/backstageTeam/pages/teamDetails/teamDetails',
    // })
  },
  allisshow: function () {
    this.setData({
      ispopup: true,
      isstate: false,
      isscreen: false,
    })
  },
  isscreen: function () {
    this.setData({
      ispopup: false,
      isstate: false,
      isscreen: true,
    })
  },
  isstates: function () {
    this.setData({
      ispopup: false,
      isstate: true,
      isscreen: false,
    })
  },
  closeallshow: function () {
    this.setData({
      ispopup: false,
      isstate: false,
      isscreen: false,
    })
  },
  allitembtn: function (e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      popupindex: index,
      ispopup: false,
      isstate: false,
      isscreen: false,
      order:index,
      page:0,
      list:[],
    })
    this.getList();

  },
  screenitembtn: function (e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      screenindex: index,
      ispopup: false,
      isstate: false,
      isscreen: false,
      status:index,
      page:0,
      list:[]
    })
    this.getList();
  },
  teamtab: function (e) {
    const index = e.currentTarget.dataset.dex;
    this.setData({
      teamindex: index
    })
  },
  createteam: function () {
    wx.navigateTo({
      url: '/hyb_yl/backstageTeam/pages/createTeam/createTeam',
    })
  },
  //tab切换
  list: function (e) {
    var that = this;
    console.log(e)
    if (e.currentTarget.dataset.id == 1) {
      console.log('123')
      that.setData({
        curHdIndex: 1
      })
    } else {
      //热门
      that.setData({
        curHdIndex: 2
      })
    }
    if (e.currentTarget.dataset.id == 2) {
      app.util.request({
        url: 'entry/wxapp/share.remen',
        data: {
          openid: wx.getStorageSync('openid'),
          state: 1
        },
        success: function (res) {
          console.log(res)
          that.setData({
            communityListOne: res.data,
          })
        }
      })
    } else {
      this.getAllshare()
    }
  },
  //上来加载
  // moreState: function() {
  //   var a = this,
  //     e = {
  //       type: a.data.curHdIndex,
  //       tsid: a.data.tsid,
  //       token: a.data.token
  //     },
  //     n = a.data.prenumber;
  //   t.default.getCommunityList(a, e, n);
  // },
  //点赞
  toLike: function (a) {
    var e = this;
    let communityListOne = e.data.communityListOne;
    var n = a.currentTarget.dataset.index
    var a_id = a.currentTarget.dataset.a_id
    var openid = wx.getStorageSync('openid')
    if (communityListOne[n].dianzan == 0) {
      app.util.request({
        'url': 'entry/wxapp/share.userdianz',
        data: {
          parentid: a_id,
          openid: openid,
        },
        success: function (res) {
          console.log(res)

        }
      })
      wx.showToast({
        title: "点赞成功",
        icon: "none",
        duration: 1500,
        success: function () {
          var dianzan = "communityListOne[" + n + "].dianzan"
          console.log(dianzan)
          e.setData({
            [dianzan]: 1
          })
        }
      });

    } else {
      wx.showToast({
        title: "点赞是严肃的，不可以反悔哦！",
        icon: "none",
        duration: 1500
      });
    }
  },

  onLoad: function (t) {
    template.tabbar("tabBar", 1, this);
    var a = this;
    var bgc = wx.getStorageSync('color')
    var hid = t.hid
    console.log(hid)
    a.setData({
      bgc: bgc,
      hid: hid
    })
    page = 1;
    a.getAllshare(page);
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    // 查询医生职称
    a.getAlldoczhicheng();
    //查询机构中的医生
    a.getList();
    // 查询科室
    a.getkeshi();
    
  },
  getkeshi:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/team.keshi_twos",
      success:function(res){
        that.setData({
          keshi_arr:res.data
        })
      }
    })
  },
  getAlldoczhicheng() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.getzhichenglist',
      success: function (res) {
        console.log(res)
        that.setData({
          doctitle: res.data
        })
      }
    })
  },
  getList() {
    var that = this;
    var hid = that.data.hid;
    var keyword = that.data.keyword;
    var order = that.data.order;
    var zhicheng = that.data.zhicheng;
    var keshi = that.data.keshi;
    var status = that.data.status;
    app.util.request({
      'url': 'entry/wxapp/team.getlistall',
      data: {
        hid: hid,
        keyword: keyword,
        order: order,
        zhicheng: zhicheng,
        keshi: keshi,
        status: status,
        page: that.data.page,
        pagesize: that.data.pagesize
      },
      success: function (res) {
        console.log(res)
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data),
          page: page
        })
      }
    })
  },
  onReady: function () {},
  onShow: function () {

  },
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {
    this.getList();
  },
  onShareAppMessage: function () {},
  //发表动态
  addCommunity: function () {
    wx.navigateTo({
      url: "/hyb_yl/userLife/pages/addDynamic/addDynamic"
    });
  },

  //查询所有分享
  getAllshare: function (_page) {
    var that = this
    app.util.request({
      url: 'entry/wxapp/share.allshare',
      data: {
        openid: wx.getStorageSync('openid'),
        page: _page,
        pagback: 5,
        state: 1
      },
      success: function (res) {
        console.log(res)
        if (res.data.length < 5) {
          that.setData({
            ismore: false
          })
        }
        var list_t = that.data.itemList;
        console.log(list_t)
        var len = res.data.length;
        for (var i = 0; i < len; i++) {
          list_t.push(res.data[i])
        }
        wx.hideLoading()
        that.setData({
          communityListOne: list_t,
          page: 1,
        })
      }
    })
  },
  previewImage: function (a) {
    var t = this;
    console.log(a)
    var i = a.currentTarget.dataset.index;
    var url = a.currentTarget.dataset.url
    var artrs = a.currentTarget.dataset.data
    console.log(i, url, artrs)
    wx.previewImage({
      current: url,
      urls: artrs
    });
  },
  scrolltolower() {
    var that = this
    console.log(that.data.ismore)
    if (that.data.ismore) {
      page++;
      console.log(page)
      that.getAllshare(page);
    }
  },
  shenhe(e) {
    console.log(e)
    var that = this
    var zid = e.currentTarget.dataset.zid
    var exa = e.currentTarget.dataset.exa
    var hid = that.data.hid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.updateexa',
      data: {
        zid: zid,
        exa: exa
      },
      success: function (res) {
        console.log(res)
        that.getList();
      }
    })
  }
});